<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员界面</title>
<style type="text/css">
	#msg{width: 260px;height: 120px;}
	#d{width: 260px;margin:10px auto;}
	#d1{float: left;}
	#d2{float: right;margin-top:10px}
</style>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/icon.css">
	<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
//删除餐厅	
function remove(){
		var row=$('#dg').datagrid('getSelected');
		$.ajax({
			url:"Res?method=removeR",
			type:"post",
			data:{
				rid:row.rid
			},
			success:function(d){
				if(d=="1"){
					$.messager.show({
						title:'提示',
						width:300,
						height:200,
						msg:'['+row.rid+']'+row.rname+'删除成功',
						timeout:3000,
						showType:'slide'
					});
					$('#dg').datagrid('reload'); 
					window.pageA.fun1();
				}
			}
		})
	}
//修改餐厅信息	
	function submitD(){
		$('#f2').form('submit', {
		    url:"Res?method=modifyR",
		    onSubmit: function(){
				return true;
		    },
		    success:function(d){
		    	if(d=="1"){
		    	var row=$('#dg').datagrid('getSelected');
		    	$.messager.show({
					title:'提示',
					width:300,
					height:200,
					msg:'['+row.rid+']'+row.rname+'修改成功',
					timeout:3000,
					showType:'slide'
				});
				$('#dg').datagrid('reload'); 
				clearD();
				$('#win2').window('close');
		    }
		    	}
		});
	}
function clearD(){
	$('#f2').form('clear');
	$('#win2').window('close');
}	


//初始化
		$(function(){
			$('#win').window('close');
			$('#win2').window('close');
			$('#dg').datagrid({
				singleSelect:true,
			    url:'Res?method=getR',
			    columns:[[
					{field:'rid',title:'店铺编号',width:60},
					{field:'rname',title:'店铺名称',width:100},
					{field:'rloc',title:'地址',width:100},
					{field:'rtel',title:'电话',width:100},
					{field:'rkey',title:'关键字',width:50},
					{field:'rbh',title:'营业时间',width:100},
					{field:'roveralls',title:'总体评分',width:80,sortable:true},
					{field:'rtastes',title:'口味评分',width:60},
					{field:'renvs',title:'环境评分',width:60},
					{field:'rsvcs',title:'服务评分',width:60},
					{field:'rtotalass',title:'评价条数',width:60},
					{field:'rimg',title:'图片地址',width:100},
					{field:'rintime',title:'收录时间',width:150},
					{field:'reason',title:'收录理由',width:100},
					{field:'uid',title:'收录人ID',width:100},
			    ]],
		    toolbar: [{
				iconCls: 'icon-edit',
				handler: function(){
					var row=$('#dg').datagrid('getSelected');
					if(row!=null){
						$('#rid').textbox('setValue',row.rid);
						$('#rname').textbox('setValue',row.rname);
						$('#rloc').textbox('setValue',row.rloc);
						$('#rtel').textbox('setValue',row.rtel);
						$('#rkey').textbox('setValue',row.rkey);
						$('#rbh').textbox('setValue',row.rbh);
						$('#rkey').combobox({
						    url:'Res?method=queryRtype',
						    valueField:'rtype',
						    textField:'rtype'	,
						    multiple:true
						})
						$('#win2').window('open');
						}
					}
			},'-',{
				iconCls: 'icon-remove',
				handler: function(){remove();}
			},'-',{
				iconCls: 'icon-add',
				handler: function(){
					location.href='approval.html';
		
				}
			}],
		});
//查询餐厅信息			
			$("#btn").click(function(){
				$('#dg').datagrid('load',{
								search1:$('#search').textbox('getValue')
							});
	});
//清空查询信息	
			$("#btn2").click(function(){
				$('#search').textbox('setValue',"");
				$('#dg').datagrid('load',{
								search:""
							});
	});
//推广	
			$("#btn3").click(function(){
				var row=$('#dg').datagrid('getSelected');
				if(row!=null){
					$('#win').window('open');
					$("#msg").val("推荐语:");
					
				}
	});
			$("#btn4").click(function(){
				var row=$('#dg').datagrid('getSelected');
				$.ajax({
					type:"post",
					url:"sendMessage",
					dataType:"json",
					data:{
						"message":"今日宝藏店铺推荐~<br />店名:"+row.rname+"<br />地址:"+row.rloc+"<br />分类:"+row.rkey+"<br />"+$("#msg").val(),
						"getter":"0"
					},
					success:function(d){
						if(d.result){
						  	$.messager.show({
								title:'提示',
								width:300,
								height:200,
								msg:'['+row.rid+']'+row.rname+'推广完成',
								timeout:2000,
								showType:'slide'
							});
						  	$("#msg").val("");
						  	$('#win').window('close');
						}
					}
				})
				
				
			})
		})
	
	</script>
</head>
<body>
	<input class="easyui-textbox" type="text" id="search" style="width:120px"></input>
	<button id="btn">搜索</button>&nbsp;<button id="btn2">刷新</button>&nbsp;<button id="btn3">推广</button>
	<table id="dg" width="1300" data-options="striped:true,pagination:true"></table>
<!-- 修改餐厅信息 -->
	<div id="win2" class="easyui-window" title="修改餐厅信息" style="width:400px;height:300px"
	    data-options="iconCls:'icon-save',modal:true">
	 <form id="f2" method="post">
	    	<table cellpadding="5">
	    	<tr>
	    			<td>店铺编号:</td>
	    			<td><input class="easyui-textbox" type="text" name="rid" id="rid" data-options="required:true,readonly:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>店铺名称:</td>
	    			<td><input class="easyui-textbox" type="text" id="rname" name="rname" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>地址:</td>
	    			<td><input class="easyui-textbox" type="text" id="rloc" name="rloc" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>电话:</td>
	    			<td><input class="easyui-textbox" type="text" id="rtel" name="rtel" data-options="required:true"></input></td>
	    		</tr>
	    		 <tr>
	    			<td>关键字:</td>
	    			<td><select class="easyui-combobox"   name="rkey" id="rkey" style="width:100px;">
	    			</select></td>
	    		</tr>
				<tr>
	    			<td>营业时间:</td>
	    			<td><input class="easyui-textbox" type="text" id="rbh" name="rbh" data-options="required:true"></input></td>
	    		</tr>
	    	</table>
	    </form>
	      <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitD()">确定</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearD()">取消</a>
	    </div>
	    </div>
	   <div id="win" class="easyui-window" title="推荐语" style="width:360px;height:230px"
	    data-options="iconCls:'icon-save',modal:true">
	 	<div id="d">
	<div id="d1"><textarea id="msg"></textarea>
	</div>
	<div id="d2">
	<button id="btn4">确定</button>
	</div>
	    </div>
	     </div> 
</body>
</html>